package com.wjk.kylin.rpc.core.config;

import com.wjk.kylin.rpc.core.invoker.impl.RpcSpringConsumerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author wjk
 */
@Configuration
@EnableConfigurationProperties({RpcConsumerConfigProperties.class})
public class RpcConsumerConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(RpcConsumerConfig.class);

    @Autowired
    private RpcConsumerConfigProperties properties;

    @Bean
    @ConditionalOnMissingBean(RpcSpringConsumerFactory.class)
    @ConditionalOnProperty(name = "kylin.rpc.consumer.enable", havingValue = "true")
    public RpcSpringConsumerFactory springConsumerFactory() {

        RpcSpringConsumerFactory consumerFactory = new RpcSpringConsumerFactory();

        consumerFactory.setProperties(properties);

        LOGGER.info(">>>>>>>>>>> kylin-rpc consumer init finish");
        return consumerFactory;
    }
}
